Make header path for kernel's privcmd/evtchn headers generic.
Remove pointless xi_*() interface that was using private libxc
interfaces.
Signed-off-by: John Levon <john.levon@sun.com>
%.o: %.cc
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
-.PHONY: mk-symlinks
-mk-symlinks: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse
-mk-symlinks:
+OS = $(shell uname -s)
+
+.PHONY: mk-symlinks mk-symlinks-xen mk-symlinks-$(OS)
+
+mk-symlinks-Linux: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse
+mk-symlinks-Linux:
+ mkdir -p xen/linux
+ ( cd xen/linux && \
+ ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . )
+ ( cd xen && rm -f sys && ln -sf linux sys )
+
+mk-symlinks-xen:
mkdir -p xen
( cd xen && ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
mkdir -p xen/hvm
( cd xen/hvm && ln -sf ../../$(XEN_ROOT)/xen/include/public/hvm/*.h . )
mkdir -p xen/io
( cd xen/io && ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
- mkdir -p xen/linux
- ( cd xen/linux && \
- ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . )
+
+mk-symlinks: mk-symlinks-xen mk-symlinks-$(OS)
#include <xenctrl.h>
#include <xen/xen.h>
#include <xen/io/domain_controller.h>
-#include <xen/linux/privcmd.h>
#include "pdb_module.h"
#include "pdb_caml_xen.h"
#include <xen/xen.h>
#include <xen/io/domain_controller.h>
-#include <xen/linux/privcmd.h>
#include <arpa/inet.h>
#include <xcs_proto.h>
SRCS += xc_domain.c
SRCS += xc_evtchn.c
SRCS += xc_misc.c
+SRCS += xc_acm.c
SRCS += xc_physdev.c
SRCS += xc_private.c
SRCS += xc_sedf.c
SRCS += xc_pagetab.c
endif
+SRCS_Linux += xc_linux.c
+
+SRCS += $(SRCS_Linux)
+
BUILD_SRCS :=
BUILD_SRCS += xc_linux_build.c
BUILD_SRCS += xc_load_bin.c
--- /dev/null
+/******************************************************************************
+ *
+ * Copyright (C) 2005 IBM Corporation
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Authors:
+ * Reiner Sailer <sailer@watson.ibm.com>
+ * Stefan Berger <stefanb@watson.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
+ */
+
+#include "xc_private.h"
+
+int xc_acm_op(int xc_handle, struct acm_op *op)
+{
+ int ret = -1;
+ DECLARE_HYPERCALL;
+
+ op->interface_version = ACM_INTERFACE_VERSION;
+
+ hypercall.op = __HYPERVISOR_acm_op;
+ hypercall.arg[0] = (unsigned long) op;
+
+ if (mlock(op, sizeof(*op)) != 0) {
+ PERROR("Could not lock memory for Xen policy hypercall");
+ goto out1;
+ }
+
+ ret = do_xen_hypercall(xc_handle, &hypercall);
+ ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall);
+ if (ret < 0) {
+ goto out2;
+ }
+ out2:
+ safe_munlock(op, sizeof(*op));
+ out1:
+ return ret;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
+ */
+
+#include "xc_private.h"
+
+#include <xen/memory.h>
+#include <xen/sys/evtchn.h>
+
+int xc_interface_open(void)
+{
+ int fd = open("/proc/xen/privcmd", O_RDWR);
+ if ( fd == -1 )
+ PERROR("Could not obtain handle on privileged command interface");
+ return fd;
+}
+
+int xc_interface_close(int xc_handle)
+{
+ return close(xc_handle);
+}
+
+void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+ unsigned long *arr, int num)
+{
+ privcmd_mmapbatch_t ioctlx;
+ void *addr;
+ addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=num;
+ ioctlx.dom=dom;
+ ioctlx.addr=(unsigned long)addr;
+ ioctlx.arr=arr;
+ if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ perror("XXXXXXXX");
+ (void)munmap(addr, num*PAGE_SIZE);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+
+}
+
+void *xc_map_foreign_range(int xc_handle, uint32_t dom,
+ int size, int prot,
+ unsigned long mfn)
+{
+ privcmd_mmap_t ioctlx;
+ privcmd_mmap_entry_t entry;
+ void *addr;
+ addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=1;
+ ioctlx.dom=dom;
+ ioctlx.entry=&entry;
+ entry.va=(unsigned long) addr;
+ entry.mfn=mfn;
+ entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
+ if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ (void)munmap(addr, size);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+}
+
+int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+ privcmd_mmap_entry_t *entries, int nr)
+{
+ privcmd_mmap_t ioctlx;
+
+ ioctlx.num = nr;
+ ioctlx.dom = dom;
+ ioctlx.entry = entries;
+
+ return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
+}
+
+static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
+{
+ return ioctl(xc_handle, cmd, data);
+}
+
+int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
+{
+ return do_privcmd(xc_handle,
+ IOCTL_PRIVCMD_HYPERCALL,
+ (unsigned long)hypercall);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
#include <unistd.h>
#include <sys/time.h>
+#include "xc_private.h"
#include "xg_private.h"
#include "xg_save_restore.h"
int prot)
{
struct xen_machphys_mfn_list xmml;
- privcmd_mmap_t ioctlx;
privcmd_mmap_entry_t *entries;
unsigned long m2p_chunks, m2p_size;
unsigned long *m2p;
return NULL;
}
- ioctlx.num = m2p_chunks;
- ioctlx.dom = DOMID_XEN;
- ioctlx.entry = entries;
-
for (i=0; i < m2p_chunks; i++) {
entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE));
entries[i].mfn = extent_start[i];
entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT;
}
- if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) {
- ERR("ioctl_mmap failed (rc = %d)", rc);
+ if ((rc = xc_map_foreign_ranges(xc_handle, DOMID_XEN,
+ entries, m2p_chunks)) < 0) {
+ ERR("xc_mmap_foreign_ranges failed (rc = %d)", rc);
return NULL;
}
#include "xc_private.h"
-int xc_interface_open(void)
-{
- int fd = open("/proc/xen/privcmd", O_RDWR);
- if ( fd == -1 )
- PERROR("Could not obtain handle on privileged command interface");
- return fd;
-}
-
-int xc_interface_close(int xc_handle)
-{
- return close(xc_handle);
-}
-
int xc_readconsolering(int xc_handle,
char **pbuffer,
unsigned int *pnr_chars,
*/
#include "xc_private.h"
-#include <xen/memory.h>
-
-void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
- unsigned long *arr, int num )
-{
- privcmd_mmapbatch_t ioctlx;
- void *addr;
- addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
- if ( addr == MAP_FAILED )
- return NULL;
-
- ioctlx.num=num;
- ioctlx.dom=dom;
- ioctlx.addr=(unsigned long)addr;
- ioctlx.arr=arr;
- if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
- {
- int saved_errno = errno;
- perror("XXXXXXXX");
- (void)munmap(addr, num*PAGE_SIZE);
- errno = saved_errno;
- return NULL;
- }
- return addr;
-
-}
-
-/*******************/
-
-void *xc_map_foreign_range(int xc_handle, uint32_t dom,
- int size, int prot,
- unsigned long mfn )
-{
- privcmd_mmap_t ioctlx;
- privcmd_mmap_entry_t entry;
- void *addr;
- addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
- if ( addr == MAP_FAILED )
- return NULL;
-
- ioctlx.num=1;
- ioctlx.dom=dom;
- ioctlx.entry=&entry;
- entry.va=(unsigned long) addr;
- entry.mfn=mfn;
- entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
- if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
- {
- int saved_errno = errno;
- (void)munmap(addr, size);
- errno = saved_errno;
- return NULL;
- }
- return addr;
-}
-
-/*******************/
/* NB: arr must be mlock'ed */
int xc_get_pfn_type_batch(int xc_handle,
#include "xenctrl.h"
-#include <xen/linux/privcmd.h>
+#include <xen/sys/privcmd.h>
/* valgrind cannot see when a hypercall has filled in some values. For this
reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
errno = saved_errno;
}
-static inline int do_privcmd(int xc_handle,
- unsigned int cmd,
- unsigned long data)
-{
- return ioctl(xc_handle, cmd, data);
-}
-
-static inline int do_xen_hypercall(int xc_handle,
- privcmd_hypercall_t *hypercall)
-{
- return do_privcmd(xc_handle,
- IOCTL_PRIVCMD_HYPERCALL,
- (unsigned long)hypercall);
-}
+int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
static inline int do_xen_version(int xc_handle, int cmd, void *dest)
{
return ret;
}
-
-/*
- * ioctl-based mfn mapping interface
- */
-
-/*
-typedef struct privcmd_mmap_entry {
- unsigned long va;
- unsigned long mfn;
- unsigned long npages;
-} privcmd_mmap_entry_t;
-
-typedef struct privcmd_mmap {
- int num;
- domid_t dom;
- privcmd_mmap_entry_t *entry;
-} privcmd_mmap_t;
-*/
+int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+ privcmd_mmap_entry_t *entries, int nr);
#endif /* __XC_PRIVATE_H__ */
* API for manipulating and accessing trace buffer parameters
*
* Copyright (c) 2005, Rob Gardner
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
*/
#include "xc_private.h"
return rc;
}
+int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn)
+{
+ int rc;
+ DECLARE_DOM0_OP;
+
+ op.cmd = DOM0_TBUFCONTROL;
+ op.interface_version = DOM0_INTERFACE_VERSION;
+ op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO;
+
+ rc = xc_dom0_op(xc_handle, &op);
+ if ( rc == 0 )
+ *mfn = op.u.tbufcontrol.buffer_mfn;
+ return rc;
+}
+
+int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
+{
+ DECLARE_DOM0_OP;
+
+ op.cmd = DOM0_TBUFCONTROL;
+ op.interface_version = DOM0_INTERFACE_VERSION;
+ op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK;
+ op.u.tbufcontrol.cpu_mask = mask;
+
+ return do_dom0_op(xc_handle, &op);
+}
+
+int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask)
+{
+ DECLARE_DOM0_OP;
+
+ op.cmd = DOM0_TBUFCONTROL;
+ op.interface_version = DOM0_INTERFACE_VERSION;
+ op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK;
+ op.u.tbufcontrol.evt_mask = mask;
+
+ return do_dom0_op(xc_handle, &op);
+}
#include <xen/sched_ctl.h>
#include <xen/memory.h>
#include <xen/acm.h>
+#include <xen/acm_ops.h>
#ifdef __ia64__
#define XC_PAGE_SHIFT 14
*/
int xc_tbuf_get_size(int xc_handle, uint32_t *size);
+/**
+ * This function retrieves the machine frame of the trace buffer.
+
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm mfn will contain the machine frame of the buffer.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn);
+
+int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask);
+
+int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask);
/* Execute a privileged dom0 operation. */
int xc_dom0_op(int xc_handle, dom0_op_t *op);
unsigned long long ptr, unsigned long long val);
int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
+int xc_acm_op(int xc_handle, struct acm_op *op);
+
#endif
#include "xenctrl.h"
#include "xenguest.h"
-#include <xen/linux/privcmd.h>
+#include <xen/sys/privcmd.h>
#include <xen/memory.h>
/* valgrind cannot see when a hypercall has filled in some values. For this
#include <netinet/in.h>
#include <xen/acm.h>
#include <xen/acm_ops.h>
-#include <xen/linux/privcmd.h>
+
+#include <xenctrl.h>
#define PERROR(_m, _a...) \
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
errno, strerror(errno))
-
-
-static inline int do_acm_op(int xc_handle, struct acm_op *op)
-{
- int ret = -1;
- privcmd_hypercall_t hypercall;
-
- op->interface_version = ACM_INTERFACE_VERSION;
-
- hypercall.op = __HYPERVISOR_acm_op;
- hypercall.arg[0] = (unsigned long) op;
-
- if (mlock(op, sizeof(*op)) != 0) {
- PERROR("Could not lock memory for Xen policy hypercall");
- goto out1;
- }
- ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall);
- if (ret < 0) {
- if (errno == EACCES)
- PERROR("ACM operation failed.");
- goto out2;
- }
- out2:
- munlock(op, sizeof(*op));
- out1:
- return ret;
-}
-
-
-
/* generic shared function */
void * __getssid(int domid, uint32_t *buflen)
{
struct acm_op op;
- int acm_cmd_fd;
+ int xc_handle;
#define SSID_BUFFER_SIZE 4096
void *buf = NULL;
- if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) < 0) {
+ if ((xc_handle = xc_interface_open()) < 0) {
goto out1;
}
if ((buf = malloc(SSID_BUFFER_SIZE)) == NULL) {
op.u.getssid.get_ssid_by = DOMAINID;
op.u.getssid.id.domainid = domid;
- if (do_acm_op(acm_cmd_fd, &op) < 0) {
+ if (xc_acm_op(xc_handle, &op) < 0) {
+ if (errno == EACCES)
+ PERROR("ACM operation failed.");
free(buf);
buf = NULL;
goto out2;
goto out2;
}
out2:
- close(acm_cmd_fd);
+ xc_interface_close(xc_handle);
out1:
return buf;
}
{
char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL;
struct acm_op op;
- int acm_cmd_fd, ret;
+ int xc_handle;
if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) {
return NULL;
}
- if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
+ if ((xc_handle = xc_interface_open()) <= 0) {
PERROR("Could not open xen privcmd device!\n");
return NULL;
}
op.u.getdecision.id2.ssidref = atol(arg2);
}
- ret = do_acm_op(acm_cmd_fd, &op);
- close(acm_cmd_fd);
+ if (xc_acm_op(xc_handle, &op) < 0) {
+ if (errno == EACCES)
+ PERROR("ACM operation failed.");
+ }
+
+ xc_interface_close(xc_handle);
if (op.u.getdecision.acm_decision == ACM_ACCESS_PERMITTED)
decision = "PERMITTED";
*
* sHype policy management tool. This code runs in a domain and
* manages the Xen security policy by interacting with the
- * Xen access control module via a /proc/xen/privcmd proc-ioctl,
+ * Xen access control module via the privcmd device,
* which is translated into a acm_op hypercall into Xen.
*
* indent -i4 -kr -nut
#include <stdint.h>
#include <xen/acm.h>
#include <xen/acm_ops.h>
-#include <xen/linux/privcmd.h>
+
+#include <xenctrl.h>
#define PERROR(_m, _a...) \
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
exit(-1);
}
-static inline int do_policycmd(int xc_handle, unsigned int cmd,
- unsigned long data)
-{
- return ioctl(xc_handle, cmd, data);
-}
-
-static inline int do_xen_hypercall(int xc_handle,
- privcmd_hypercall_t * hypercall)
-{
- return do_policycmd(xc_handle,
- IOCTL_PRIVCMD_HYPERCALL,
- (unsigned long) hypercall);
-}
-
-static inline int do_acm_op(int xc_handle, struct acm_op *op)
-{
- int ret = -1;
- privcmd_hypercall_t hypercall;
-
- op->interface_version = ACM_INTERFACE_VERSION;
-
- hypercall.op = __HYPERVISOR_acm_op;
- hypercall.arg[0] = (unsigned long) op;
-
- if (mlock(op, sizeof(*op)) != 0) {
- PERROR("Could not lock memory for Xen policy hypercall");
- goto out1;
- }
-
- if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0) {
- printf("ACM operation failed: errno=%d\n", errno);
- if (errno == EACCES)
- fprintf(stderr, "ACM operation failed -- need to"
- " rebuild the user-space tool set?\n");
- goto out2;
- }
-
- out2:(void) munlock(op, sizeof(*op));
- out1:return ret;
-}
-
/*************************** DUMPS *******************************/
void acm_dump_chinesewall_buffer(void *buf, int buflen)
memset(pull_buffer, 0x00, sizeof(pull_buffer));
op.cmd = ACM_GETPOLICY;
- op.interface_version = ACM_INTERFACE_VERSION;
op.u.getpolicy.pullcache = (void *) pull_buffer;
op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
- ret = do_acm_op(xc_handle, &op);
+ if ((ret = xc_acm_op(xc_handle, &op)) < 0) {
+ printf("ACM operation failed: errno=%d\n", errno);
+ if (errno == EACCES)
+ fprintf(stderr, "ACM operation failed -- need to"
+ " rebuild the user-space tool set?\n");
+ }
+
/* dump policy */
acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer));
return ret;
/* dump it and then push it down into xen/acm */
acm_dump_policy_buffer(buffer, len);
op.cmd = ACM_SETPOLICY;
- op.interface_version = ACM_INTERFACE_VERSION;
op.u.setpolicy.pushcache = (void *) buffer;
op.u.setpolicy.pushcache_size = len;
- ret = do_acm_op(xc_handle, &op);
+ ret = xc_acm_op(xc_handle, &op);
if (ret)
printf
memset(stats_buffer, 0x00, sizeof(stats_buffer));
op.cmd = ACM_DUMPSTATS;
- op.interface_version = ACM_INTERFACE_VERSION;
op.u.dumpstats.pullcache = (void *) stats_buffer;
op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
- ret = do_acm_op(xc_handle, &op);
+ ret = xc_acm_op(xc_handle, &op);
if (ret < 0) {
printf
int main(int argc, char **argv)
{
- int acm_cmd_fd, ret = 0;
+ int xc_handle, ret = 0;
if (argc < 2)
usage(argv[0]);
- if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
+ if ((xc_handle = xc_interface_open()) <= 0) {
printf("ERROR: Could not open xen privcmd device!\n");
exit(-1);
}
if (!strcmp(argv[1], "getpolicy")) {
if (argc != 2)
usage(argv[0]);
- ret = acm_domain_getpolicy(acm_cmd_fd);
+ ret = acm_domain_getpolicy(xc_handle);
} else if (!strcmp(argv[1], "loadpolicy")) {
if (argc != 3)
usage(argv[0]);
- ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]);
+ ret = acm_domain_loadpolicy(xc_handle, argv[2]);
} else if (!strcmp(argv[1], "dumpstats")) {
if (argc != 2)
usage(argv[0]);
- ret = acm_domain_dumpstats(acm_cmd_fd);
+ ret = acm_domain_dumpstats(xc_handle);
} else
usage(argv[0]);
- close(acm_cmd_fd);
+ xc_interface_close(xc_handle);
return ret;
}
struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
unsigned long size)
{
- int xc_handle; /* file descriptor for /proc/xen/privcmd */
+ int xc_handle;
struct t_buf *tbufs_mapped;
xc_handle = xc_interface_open();
if ( xc_handle < 0 )
{
- PERROR("Open /proc/xen/privcmd when mapping trace buffers\n");
exit(EXIT_FAILURE);
}
LIB=src/libxenstat.a
SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR)
SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so
-OBJECTS=src/xenstat.o src/xen-interface.o
+OBJECTS=src/xenstat.o
SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR)
WARN_FLAGS=-Wall -Werror
CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE)
-LDFLAGS+=-Lsrc
+LDFLAGS+=-Lsrc -L$(XEN_XENSTORE)/ -L$(XEN_LIBXC)/
.PHONY: all
all: $(LIB)
$(LIB): $(OBJECTS)
- $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so
+ $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so $(XEN_LIBXC)/libxenctrl.so
$(RANLIB) $@
$(SHLIB): $(OBJECTS)
- $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS)
+ $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) \
+ -lxenstore -lxenctrl
-src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h
- $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
-
-src/xen-interface.o: src/xen-interface.c src/xen-interface.h
+src/xenstat.o: src/xenstat.c src/xenstat.h
$(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
src/libxenstat.so.$(MAJOR): $(LIB)
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <xen-interface.h>
#include <xs.h>
#include "xenstat.h"
+#include "xenctrl.h"
+
/*
* Types
*/
#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
struct xenstat_handle {
- xi_handle *xihandle;
+ int xc_handle;
struct xs_handle *xshandle; /* xenstore handle */
int page_size;
FILE *procnetdev;
}
#endif
- handle->xihandle = xi_init();
- if (handle->xihandle == NULL) {
- perror("xi_init");
+ handle->xc_handle = xc_interface_open();
+ if (handle->xc_handle == -1) {
+ perror("xc_interface_open");
free(handle);
return NULL;
}
handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
if (handle->xshandle == NULL) {
perror("unable to open xenstore\n");
+ xc_interface_close(handle->xc_handle);
free(handle);
return NULL;
}
if (handle) {
for (i = 0; i < NUM_COLLECTORS; i++)
collectors[i].uninit(handle);
- xi_uninit(handle->xihandle);
+ xc_interface_close(handle->xc_handle);
xs_daemon_close(handle->xshandle);
free(handle);
}
node->handle = handle;
/* Get information about the physical system */
- if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) {
+ if (xc_physinfo(handle->xc_handle, &physinfo) < 0) {
free(node);
return NULL;
}
do {
xenstat_domain *domain;
- new_domains = xi_get_domaininfolist(handle->xihandle,
- domaininfo, num_domains,
- DOMAIN_CHUNK_SIZE);
+ new_domains = xc_domain_getinfolist(handle->xc_handle,
+ num_domains, DOMAIN_CHUNK_SIZE, domaininfo);
node->domains = realloc(node->domains,
(num_domains + new_domains)
/* FIXME: need to be using a more efficient mechanism*/
dom0_getvcpuinfo_t info;
- if (xi_get_domain_vcpu_info(node->handle->xihandle,
- node->domains[i].id, vcpu, &info) != 0)
+ if (xc_vcpu_getinfo(node->handle->xc_handle,
+ node->domains[i].id, vcpu, &info) != 0)
return 0;
node->domains[i].vcpus[vcpu].online = info.online;
/* Collect Xen version information if not already collected */
if (node->handle->xen_version[0] == '\0') {
/* Get the Xen version number and extraversion string */
- if (xi_get_xen_version(node->handle->xihandle,
- &vnum, &version) < 0)
+ vnum = xc_version(node->handle->xc_handle,
+ XENVER_version, NULL);
+
+ if (vnum < 0)
+ return 0;
+
+ if (xc_version(node->handle->xc_handle, XENVER_extraversion,
+ &version) < 0)
return 0;
/* Format the version information as a string and store it */
snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
#include <errno.h>
#include <argp.h>
#include <signal.h>
+#include <inttypes.h>
+#include <string.h>
-#include "xc_private.h"
-
+#include <xen/xen.h>
#include <xen/trace.h>
+#include <xenctrl.h>
+
+#define PERROR(_m, _a...) \
+do { \
+ int __saved_errno = errno; \
+ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
+ __saved_errno, strerror(__saved_errno)); \
+ errno = __saved_errno; \
+} while (0)
+
extern FILE *stderr;
/***** Compile time configuration of defaults ********************************/
*/
void get_tbufs(unsigned long *mfn, unsigned long *size)
{
- int ret;
- dom0_op_t op; /* dom0 op we'll build */
+ uint32_t size32;
int xc_handle = xc_interface_open(); /* for accessing control interface */
- op.cmd = DOM0_TBUFCONTROL;
- op.interface_version = DOM0_INTERFACE_VERSION;
- op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO;
+ if (xc_tbuf_get_size(xc_handle, &size32) != 0)
+ goto fail;
+ *size = size32;
- ret = do_dom0_op(xc_handle, &op);
+ if (xc_tbuf_get_mfn(xc_handle, mfn) != 0)
+ goto fail;
xc_interface_close(xc_handle);
+ return;
- if ( ret != 0 )
- {
- PERROR("Failure to get trace buffer pointer from Xen");
- exit(EXIT_FAILURE);
- }
-
- *mfn = op.u.tbufcontrol.buffer_mfn;
- *size = op.u.tbufcontrol.size;
+fail:
+ PERROR("Failure to get trace buffer pointer from Xen");
+ exit(EXIT_FAILURE);
}
/**
struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
unsigned long size)
{
- int xc_handle; /* file descriptor for /proc/xen/privcmd */
+ int xc_handle;
struct t_buf *tbufs_mapped;
xc_handle = xc_interface_open();
if ( xc_handle < 0 )
{
- PERROR("Open /proc/xen/privcmd when mapping trace buffers\n");
exit(EXIT_FAILURE);
}
*/
void set_mask(uint32_t mask, int type)
{
- int ret;
- dom0_op_t op; /* dom0 op we'll build */
+ int ret = 0;
int xc_handle = xc_interface_open(); /* for accessing control interface */
- op.cmd = DOM0_TBUFCONTROL;
- op.interface_version = DOM0_INTERFACE_VERSION;
- if (type == 1) { /* cpu mask */
- op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK;
- op.u.tbufcontrol.cpu_mask = mask;
+ if (type == 1) {
+ ret = xc_tbuf_set_cpu_mask(xc_handle, mask);
fprintf(stderr, "change cpumask to 0x%x\n", mask);
- }else if (type == 0) { /* event mask */
- op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK;
- op.u.tbufcontrol.evt_mask = mask;
+ } else if (type == 0) {
+ ret = xc_tbuf_set_evt_mask(xc_handle, mask);
fprintf(stderr, "change evtmask to 0x%x\n", mask);
}
- ret = do_dom0_op(xc_handle, &op);
-
xc_interface_close(xc_handle);
if ( ret != 0 )
PERROR("Failure to get trace buffer pointer from Xen and set the new mask");
exit(EXIT_FAILURE);
}
-
}
/**
*/
unsigned int get_num_cpus(void)
{
- dom0_op_t op;
+ xc_physinfo_t physinfo;
int xc_handle = xc_interface_open();
int ret;
- op.cmd = DOM0_PHYSINFO;
- op.interface_version = DOM0_INTERFACE_VERSION;
-
- ret = do_dom0_op(xc_handle, &op);
+ ret = xc_physinfo(xc_handle, &physinfo);
if ( ret != 0 )
{
xc_interface_close(xc_handle);
- return (op.u.physinfo.threads_per_core *
- op.u.physinfo.cores_per_socket *
- op.u.physinfo.sockets_per_node *
- op.u.physinfo.nr_nodes);
+ return (physinfo.threads_per_core *
+ physinfo.cores_per_socket *
+ physinfo.sockets_per_node *
+ physinfo.nr_nodes);
}